USE AdventureWorks2008
GO

DECLARE @CurrentTerritory hierarchyid , @OldParent hierarchyid, @NewParent hierarchyid
SELECT @CurrentTerritory = OrgNode FROM Sales.SalesTerritoryOrg
  WHERE TerritoryID = 5 ; 
SELECT @OldParent = OrgNode FROM Sales.SalesTerritoryOrg
  WHERE TerritoryID = 1 ; 
SELECT @NewParent = OrgNode FROM Sales.SalesTerritoryOrg
  WHERE TerritoryID = 3 ; 

UPDATE Sales.SalesTerritoryOrg
SET OrgNode = @CurrentTerritory. GetReparentedValue(@OldParent, @NewParent) 
WHERE OrgNode = @CurrentTerritory ;
GO
